package com.sqsf.test;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//spring与web环境整合-基础代码书写
//直接在servlet方法中加载创建spring容器对象 并进行使用
@WebServlet("/a")
public class AServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //加载spring核心配置文件创建spring容器对象
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        //获取spring容器中的对象并使用
        User bean = applicationContext.getBean(User.class);
        System.out.println(bean);
        //关闭spring容器对象
        applicationContext.close();
    }
}
